Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show_from profile filter. #372

Merged
merged 11 commits into from
May 8, 2018
Merged

Add show_from profile filter. #372

merged 11 commits into from
May 8, 2018

Conversation

lvng
Copy link
Contributor

@lvng lvng commented May 3, 2018

This change adds the show_from filter, which drops frames before the first match in each stack, beginning from the root.

This fixes #363.

…r raw and proto commands. updated the driver test case to match demangled function name. fixed code formatting.
@codecov-io
Copy link

codecov-io commented May 3, 2018

Codecov Report

Merging #372 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #372      +/-   ##
==========================================
+ Coverage   66.73%   66.88%   +0.14%     
==========================================
  Files          36       36              
  Lines        7462     7495      +33     
==========================================
+ Hits         4980     5013      +33     
  Misses       2080     2080              
  Partials      402      402
Impacted Files Coverage Δ
internal/driver/commands.go 44.5% <ø> (ø) ⬆️
internal/driver/driver.go 70.43% <100%> (ø) ⬆️
internal/driver/driver_focus.go 85.24% <100%> (+0.37%) ⬆️
profile/filter.go 87.21% <100%> (+3.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 854c7e5...2e80e4e. Read the comment docs.

@@ -185,6 +185,10 @@ var pprofVariables = variables{
"Only show nodes matching regexp",
"If set, only show nodes that match this location.",
"Matching includes the function name, filename or object name.")},
"show_from": &variable{stringKind, "", "", helpText(
"Drops nodes above the highest matched node of every sample.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd replace "node" with "frame" since the rest of the text uses that. Maybe try to make the description also a bit more like description of prune_from in style since these two are symmetric in a way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -193,6 +195,9 @@ func applyCommandOverrides(cmd []string, v variables) variables {
v.set("hide", "")
v.set("show", "")
}
if !showFrom {
v.set("show_from", "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding showFrom var and separate check and not just put this line after v.set("show", "")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure whether to include it in the focus or hide section. it seems those flags are semantically equivalent so i combined focus, hide, and showFrom into a single flag "filter".

@@ -247,6 +248,7 @@ func testSourceURL(port int) string {

// solutionFilename returns the name of the solution file for the test
func solutionFilename(source string, f *testFlags) string {
fmt.Printf("solution flags: %v\n", f)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. fixed.

@@ -74,6 +74,97 @@ func (p *Profile) FilterSamplesByName(focus, ignore, hide, show *regexp.Regexp)
return
}

// ShowFrom drops all stack frames before the first match from the root and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we say "first" here but "highest" in the documentation for the option. I'd try to be consistent in the terminology.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to "highest"

// returns whether a match was found. If showFrom is nil it returns false and
// does not modify the profile.
//
// Example: consider a sample with frames [A, B, C], where A is the root.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have example with multiple matches, otherwise you do not demonstrate the "highest" / "first" point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a duplicate B frame to illustrate matching multiple frames.

showFromLocs := make(map[uint64]bool)

// Apply to locations.
for _, location := range p.Location {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: location -> loc like in other functions in this file, to be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -392,6 +414,113 @@ func TestFilter(t *testing.T) {
}
}

func TestShowFrom(t *testing.T) {
for _, tc := range []struct {
// name is the name of the test case.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and next two comments on the fields are not informative, I'd drop them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

} {
t.Run(tc.name, func(t *testing.T) {
p := tc.profile.Copy()
gotMatch := p.ShowFrom(tc.showFrom)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge the assignment into the if statement on next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

gotMatch := p.ShowFrom(tc.showFrom)

if gotMatch != tc.wantMatch {
t.Errorf("match got %+v want %+v", gotMatch, tc.wantMatch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma before "want"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -392,6 +414,113 @@ func TestFilter(t *testing.T) {
}
}

func TestShowFrom(t *testing.T) {
for _, tc := range []struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have test cases that check that "show from" shows frames from the highest match? It is not obvious from the test names that any test does that. Need a test for both locations and lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added two test cases. one for matching multiple frames without inlines, and one with inlines.

@lvng
Copy link
Contributor Author

lvng commented May 4, 2018

PTAL.

@@ -150,11 +150,11 @@ func generateReport(p *profile.Profile, cmd []string, vars variables, o *plugin.
}

func applyCommandOverrides(cmd []string, v variables) variables {
trim, focus, tagfocus, hide := v["trim"].boolValue(), true, true, true
trim, tagfocus, filter := v["trim"].boolValue(), true, true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename "tagfocus" to "tagfilter", I think it will be clearer, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

// filterShowFromLocation tests a showFrom regex against a location, removes
// lines after the last match and returns whether a match was found. If the
// mapping is matched, then all lines are kept.
func filterShowFromLocation(loc *Location, showFrom *regexp.Regexp) (matched bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think named return parameter doesn't give here much. I'd just return a bool and then do "return true" and return false" as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

}
if i := loc.lastMatchedLineIndex(showFrom); i >= 0 {
matched = true
loc.Line = loc.Line[0 : i+1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: specifying zero is not required: loc.Line[:i+1]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

aalexand
aalexand previously approved these changes May 4, 2018
@aalexand
Copy link
Collaborator

aalexand commented May 7, 2018

@lvng Could you also include the new flag in the docs in https://github.com/google/pprof/tree/master/doc#options?

doc/README.md Outdated
@@ -94,6 +94,8 @@ Some common pprof options are:
*regex*.
* **-ignore= _regex_:** Do not include samples that include a report entry matching
*regex*.
* **-show\_from= _regex_:** Do not show entries above the first frame that
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say "above the first one" as it doesn't look like the text here uses term "frame".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@aalexand aalexand merged commit a50cffb into google:master May 8, 2018
KISSMonX pushed a commit to KISSMonX/pprof that referenced this pull request Jun 14, 2018
* 'master' of github.com:google/pprof: (32 commits)
  record diff base profile label key/value constant (google#384)
  apply additional command overrides based on report format (google#381)
  profile: fix legacy format Go heap profile parsing (google#382)
  add -diff flag for better profile comparision (google#369)
  Use -u flag in pprof installation command so that it updates if needed. (google#376)
  Add GetBase support for ASLR kernel mappings (google#371)
  Add show_from profile filter. (google#372)
  Update README.md due to 8dff45d (google#375)
  Remove stale docs, move useful ones. (google#374)
  internal/driver: skip tests requiring tcp on js (google#373)
  Add "trim path" option which can be used to relocate sources. (google#366)
  Move update_d3flamegraph.sh script from the root directory. (google#370)
  Skip unsymbolizable mapping during symbolz pass. (google#368)
  remove -positive_percentages flag (google#365)
  Render icicle graph in "Flame Graph" view (google#367)
  Add command-line editing support for interactive pprof (google#362)
  Improve profile filter unit tests, fix show filtering of mappings (google#354)
  Fake mappings should be merged into a single one during merging (google#357)
  Hack the code so that both existing Go versions and current Go master format it the same (google#358)
  moved filter tests into their own test file which matches the implementation file, filter.go. (google#356)
  ...
gmarin13 pushed a commit to gmarin13/pprof that referenced this pull request Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for show-from filter
4 participants